import { DependencyContainer, InjectionToken, container } from "tsyringe";

export function tryGet<T>(token: InjectionToken<T>, injector?: DependencyContainer): T {
    try {
        if(injector) return injector.resolve(token)
        return container.resolve(token)
    } catch (e) {
        throw e;
    }
}

export function tryGetSafe<T>(token: InjectionToken<T>, def: T, injector?: DependencyContainer): T {
    try {
        if(injector) return injector.resolve(token)
        return container.resolve(token)
    } catch (e) {
        return def;
    }
}
